package com.golang.api.dto.response.order;

import com.golang.api.domain.OrderItem;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.math.BigDecimal;
import java.util.Objects;

@Data
@Slf4j
public class CreateOrderItemDto {

    //票种名称
    private String ticketName;

    //下单时间
    private BigDecimal price;

    //购买数量
    private Integer quantity;


    public static CreateOrderItemDto convertDTO(OrderItem orderItem){
        if(Objects.nonNull(orderItem)){
            try{
                CreateOrderItemDto dto = new CreateOrderItemDto();
                dto.setTicketName(orderItem.getTicketName());
                dto.setPrice(orderItem.getPrice());
                dto.setQuantity(orderItem.getQuantity());

                return dto;
            }catch(Exception e) {
                log.error("OrderItem 转 CreateOrderItemDto 出错,错误信息:{}",e.getMessage(),e);
            }
        }
        return null;
    }


}
